package com.example.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.boot.env.OriginTrackedMapPropertySource;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.annotation.Order;
import org.springframework.core.env.ConfigurableEnvironment;
import org.springframework.core.env.MutablePropertySources;
import org.springframework.core.env.PropertySource;

import java.util.Map;

@Configuration
@Order(Integer.MIN_VALUE+11)
public class EnableEncryptionData implements BeanFactoryPostProcessor {

    private static ConfigurableEnvironment environment;

    public static void register(ConfigurableEnvironment env){
        environment=env;
    }

    @Override
    public void postProcessBeanFactory(ConfigurableListableBeanFactory configurableListableBeanFactory) throws BeansException {
        System.out.println(configurableListableBeanFactory);
//        MutablePropertySources propertySources = environment.getPropertySources();
//        for (PropertySource<?> propertySource : propertySources) {
//            if (propertySource instanceof OriginTrackedMapPropertySource){
//                OriginTrackedMapPropertySource om=(OriginTrackedMapPropertySource)propertySource;
//                Map<String, Object> source = om.getSource();
//                source.forEach((k,v)->{
//                    String property = environment.getProperty(k);
//                    if (property.startsWith("PWD@")){
//                        String replace = property.replace("PWD@", "");
//                        source.put(k,replace+"thispwd");
//                    }
//                });
//            }
//        }
    }

}
